﻿@model FCDB.Entity.FormCDB
@using FB.Extensions;
@{
    ViewBag.Title = "担保流程综合室输入";
    Layout = "~/Views/Shared/_FormLayout.cshtml";
    var IsViewMode = Model.Status != (short)FCDB.Entity.FormStatusEnum.Empty && Model.Status != (short)FCDB.Entity.FormStatusEnum.Draft;

}
@section HeadIncluder
{
    <link href='@Url.Content("~/Content/public.css")' rel="stylesheet" />
    <link href='@Url.Content("~/Content/con_style.css")' rel="stylesheet" />
}
<div class="f_btn">
    <div class="f_btnc">
        <button type="button" onclick="Save()" class="fj btn_c3 btn_s">保存</button>
        <button type="button" onclick="Close()" class="fj btn_c3 btn_s">关闭</button>

    </div>
</div>
<div class="frombox" id="formMain">
    <div class="from_l" style="background: #fff;">
        <div class="left_con_f PrintArea">

            <div align="center" class="left_f_tit">担保业务综合室输入</div>
            @using (Html.BeginForm("SaveComprehensive", "Form", FormMethod.Post, new { id = "frm" }))
            {
                <input type="hidden" name="ProcessGuid" value='@Request["ProcessGuid"]' />
                <input type="hidden" name="ID" value="@Model.ID" />
                <input type="hidden" name="FormGuid" value="@Model.FormGuid" />
                <input type="hidden" name="Status" value="@Model.Status" />
                Html.RenderPartial("UCHiddenArea");
                <table width="100%" class="left_xx">
                    <tr>
                        <td class="text_w" align="center">
                            流程名称：
                        </td>
                        <td colspan="5">
                            @if (IsViewMode)
                            {
                                @Model.FormTitle
                            }
                            else
                            {
                                <input id="txtFormTitle" style="width:98%;" class="validate[required] in_c1 " type="text" name="FormTitle" value="@Model.FormTitle" />
                            }
                        </td>
                    </tr>
                    <tr>
                        <td class="text_w" align="center">申请部门</td>
                        <td colspan="1">
                            @if (IsViewMode)
                            {
                                @ViewBag.DepartmentName
                            }
                            else
                            {
                                <input type="text" disabled="disabled" style="width:100px" id="DepartmentName" class="in_c1" value="@ViewBag.DepartmentName" name="DepartmentName" />
                                <input id="DepartmentID" type="hidden" name="DepartmentID" value="@Model.DepartmentID" />
                            }
                        </td>
                        <td class="text_w" align="center">流程申请人</td>
                        <td colspan="1">
                            @if (IsViewMode)
                            {
                                @ViewBag.UserName
                            }
                            else
                            {
                                <input type="text" class="in_c1" style="width:100px" disabled="disabled" id="UserName" name="UserName" value="@ViewBag.UserName" />
                                <input id="ApplyUserID" type="hidden" name="ApplyUserID" value="@Model.ApplyUserID" />
                            }
                        </td>
                        <td class="text_w" align="center">业务员</td>
                        <td colspan="1">
                            @if (IsViewMode)
                            {
                                @ViewBag.Salesman
                            }
                            else
                            {
                                <input type="text" class="in_c1" style="width:70px" id="ShowSalesman" readonly="readonly" name="ShowSalesman" value="@ViewBag.Salesman" />
                                <input id="Salesman" type="hidden" name="Salesman" value="@Model.Salesman" />
                                <a href="javascript:void(0)" class="btn_c3 " onclick="addUsers()">添加</a>
                            }
                        </td>
                    </tr>
                    <tr>
                        <td class="text_w" align="center">协议保函编号</td>
                        <td>
                            @if (IsViewMode)
                            {
                                @Model.pact_no
                            }
                            else
                            {
                                <input type="text" id="pact_no" name="pact_no" readonly="readonly" class="in_c1 " style="width:98%" value="@Model.pact_no" />
                            }
                        </td>
                        <td class="text_w" align="center">案号</td>
                        <td>
                            @if (IsViewMode)
                            {
                                @Model.CaseNumber
                            }
                            else
                            {
                                <input type="text" id="CaseNumber" name="CaseNumber" class="in_c1 " style="width:98%" value="@Model.CaseNumber" />
                            }
                        </td>
                        <td class="text_w" align="center">仲裁案号</td>
                        <td>
                            @if (IsViewMode)
                            {
                                @Model.ArbitrationNumber
                            }
                            else
                            {
                                <input type="text" id="ArbitrationNumber" name="ArbitrationNumber" placeholder="非必填" class=" in_c1 " style=" width:98%" value="@Model.ArbitrationNumber" />
                            }
                        </td>
                    </tr>
                    <tr>
                        <td class="text_w" align="center">标的金额</td>
                        <td>
                            @if (IsViewMode)
                            {
                                @Model.Amount
                            }
                            else
                            {
                                <input type="text" id="Amount" name="Amount" class="validate[required] in_c1 " onchange="CalRate()" style="width:98%" value="@Model.Amount" />
                            }
                        </td>
                        <td class="text_w" align="center">是否开发票 <a style="color:red;position:relative; top:3px">*</a></td>
                        <td>
                            @if (IsViewMode)
                            {
                                @(Model.InvoiceType == 0 ? "否" : (Model.InvoiceType == 1 ? "是，应付佣金算税费" : "是，合同收款算税费"))
                            }
                            else
                            {
                                <select id="InvoiceType" name="InvoiceType" class="validate[required] in_c1" style="width:66px" onchange="CalRate()">
                                    <option value="0">否</option>
                                    <option value="1">是，应付佣金算税费 </option>
                                    <option value="2">是，合同收款算税费</option>
                                </select>
                            }
                        </td>

                        <td class="text_w" align="center">合同收款</td>
                        <td>
                            @if (IsViewMode)
                            {
                                @Model.ContractAmount
                            }
                            else
                            {
                                <input type="text" id="ContractAmount" name="ContractAmount" onchange="CalRate()" class="validate[required] in_c1 " style="width:98%" value="@Model.ContractAmount" />
                            }
                        </td>
                    </tr>

                    <tr>
                        <td class="text_w" align="center">费率</td>
                        <td>
                            @if (IsViewMode)
                            {
                                @Model.Rate
                            }
                            else
                            {
                                <input type="text" id="Rate" name="Rate" readonly="readonly" class="validate[required] in_c1 " style="width:85%" value="@Model.Rate" />
                            }
                            %
                        </td>
                        <td class="text_w" align="center">实际收费</td>
                        <td>
                            @if (IsViewMode)
                            {
                                @Model.ActualCharge
                            }
                            else
                            {
                                <input type="text" id="ActualCharge" name="ActualCharge" onchange="CalRate()" readonly="readonly" class="validate[required] in_c1 " style="width:98%" value="@Model.ActualCharge" />
                            }
                        </td>
                        <td class="text_w" align="center">实际费率</td>
                        <td>
                            @if (IsViewMode)
                            {
                                @Model.ActualRate
                            }
                            else
                            {
                                <input type="text" id="ActualRate" name="ActualRate" readonly="readonly" class="validate[required] in_c1 " style="width:85%" value="@Model.ActualRate" />
                            }
                            %
                        </td>
                    </tr>
                    <tr>
                        <td class="text_w" align="center">应付佣金 <a style="color:red;position:relative; top:3px">*</a></td>
                        <td>
                            @if (IsViewMode)
                            {
                                @Model.PayableAmount
                            }
                            else
                            {
                                <input type="text" id="PayableAmount" name="PayableAmount" readonly="readonly" onchange="CalRate()" class="validate[required] in_c1 " style="width:98%" value="@Model.PayableAmount" />
                            }
                        </td>
                        <td class="text_w" align="center">实付中介费</td>
                        <td colspan="1">
                            @if (IsViewMode)
                            {
                                @Model.PaidAmount
                            }
                            else
                            {
                                <input type="text" id="PaidAmount" name="PaidAmount" readonly="readonly" class="validate[required] in_c1 " style="width:98%" value="@Model.PaidAmount" />
                            }
                        </td>
                        <td class="text_w" align="center">联保情况 <a style="color:red;position:relative; top:3px">*</a></td>
                        <td colspan="1">
                            @if (IsViewMode)
                            {
                                @Model.GuaranteeSituation
                            }
                            else
                            {
                                <input type="text" id="GuaranteeSituation" name="GuaranteeSituation" class="validate[required] in_c1 " style="width:98%" value="@Model.GuaranteeSituation" />
                            }
                        </td>
                    </tr>
                    <tr id="showStatus" @if (IsViewMode) { @(Model.InvoiceType == 0 ? "style=display:none" : "")  }>
                        <td class="text_w" align="center">应扣税费</td>
                        <td colspan="5">
                            @if (IsViewMode)
                            {
                                @Model.Taxation
                            }
                            else
                            {
                                <input type="text" id="Taxation" name="Taxation" readonly="readonly" class="validate[required] in_c1 " style="width:98%" value="@Model.Taxation" />
                            }
                        </td>

                    </tr>

                    <tr>
                        <td class="text_w" align="center">保函类型 <a style="color:red;position:relative; top:3px">*</a></td>
                        <td colspan="5">
                            @if (IsViewMode)
                            {
                                @(Model.GuaranteeType)
                            }
                            else
                            {
                                <select id="GuaranteeType" name="GuaranteeType" class="validate[required] in_c1" style="width:100px">
                                    <option value="一般案件" @(Model.GuaranteeType == "一般案件" ? "selected=selected" : "")>一般案件</option>
                                    <option value="联保案件" @(Model.GuaranteeType == "联保案件" ? "selected=selected" : "")>联保案件</option>
                                    <option value="保险案件" @(Model.GuaranteeType == "保险案件" ? "selected=selected" : "")>保险案件</option>
                                </select>
                            }
                        </td>
                    </tr>

                    <tr>
                        <td class="text_w" align="center">案由</td>
                        <td colspan="2">
                            @if (IsViewMode)
                            {
                                @Model.CauseOfAction
                            }
                            else
                            {
                                <input type="text" id="CauseOfAction" name="CauseOfAction" class="validate[required] in_c1 " style="width:98%" value="@Model.CauseOfAction" />
                            }
                        </td>
                        <td class="text_w" align="center">保证金</td>
                        <td colspan="2">
                            @if (IsViewMode)
                            {
                                @Model.Bond
                            }
                            else
                            {
                                <input type="text" id="Bond" name="Bond" class="in_c1 " style="width:98%" value="@Model.Bond" />
                            }
                        </td>

                    </tr>

                    <tr>
                    <tr>
                        <td rowspan="5" class="text_w" align="center">07.综合室审核</td>
                        <td class="text_w" align="center">主审法官</td>
                        <td colspan="1">

                            <input type="text" id="Judge" name="Judge" class=" in_c1 " style="width:98%" value="@Model.Judge" />

                        </td>
                        <td class="text_w" align="center">业绩归属年月</td>
                        <td colspan="2">

                            <input type="text" id="AchievementTime" name="AchievementTime" class=" in_c1 " style="width:98%" value="@(Model.AchievementTime == null ? DateTime.Now.ToString(" yyyy-MM") : Model.AchievementTime.Value.ToString(" yyyy-MM"))" />

                        </td>
                    </tr>
                    <tr>
                        <td class="text_w" align="center">案件状态</td>
                        <td colspan="1">

                            <input type="text" id="CaseStatus" name="CaseStatus" class=" in_c1 " style="width:98%" value="@Model.CaseStatus" />

                        </td>
                        <td class="text_w" align="center">龙岗数据报送</td>
                        <td colspan="2">

                            <input type="text" id="DataSend" name="DataSend" class=" in_c1 " style="width:98%" value="@Model.DataSend" />

                        </td>
                    </tr>
                    <tr>
                        <td class="text_w" align="center">提成是否发放</td>
                        <td colspan="1">
                            <select id="CommissionSend" name="CommissionSend" class="in_c1" style="width:66px">
                                <option value="true" @(Model.CommissionSend == null || Model.CommissionSend.Value ? "selected=selected" : "")>是</option>
                                <option value="false" @(Model.CommissionSend == null || Model.CommissionSend.Value ? "" : "selected=selected")>否</option>
                            </select>

                        </td>
                        <td class="text_w" align="center">释放额度情况</td>
                        <td colspan="2">

                            <input type="text" id="Quota" name="Quota" class=" in_c1 " style="width:98%" value="@Model.Quota" />

                        </td>

                    </tr>
                    <tr>
                        <td class="text_w" align="center">提成金额</td>
                        <td class="text_w"> <input type="text" id="CommissionApr" name="CommissionApr" class="in_c1 " style="width:50%" value="@Model.CommissionApr" /></td>
                        <td class="text_w" align="center">综合部备注 <a style="color:red;position:relative; top:3px">*</a></td>
                        <td colspan="2">
                            <input type="text" id="GeneralRemark" name="GeneralRemark" class="in_c1 " style="width:98%" value="@Model.GeneralRemark" />
                        </td>
                    </tr>
                    <tr>
                        <td class="text_w" align="center">负责人</td>
                        <td colspan="1">
                            <input type="text" disabled="disabled" style="width: 70px" id="HeadName" class="in_c1" value="@ViewBag.HeadName" name="HeadName" />
                            <input id="HeadID" type="hidden" name="HeadID" value="@Model.HeadID" />
                            <a href="javascript:void(0)" class="btn_c3 " onclick="addHeadUsers()">添加</a>
                        </td>
                        <td class="text_w" align="center">负责人提成比例</td>
                        <td colspan="2">
                            <input type="text" class="in_c1" style="width:70px" id="HeadApr" name="HeadApr" value="@Model.HeadApr" />%
                        </td>
                    </tr>

                    <tr>
                        <td class="text_w" align="center">A角</td>
                        <td colspan="1">
                            <input type="text" class="in_c1" style="width: 70px" disabled="disabled" id="AName" name="AName" value="@ViewBag.AName" placeholder="没有就不填" />
                            <input id="RoleAID" type="hidden" name="RoleAID" value="@Model.RoleAID" />
                            <a href="javascript:void(0)" class="btn_c3 " onclick="addAUsers()">添加</a>
                        </td>
                        <td class="text_w" align="center">A角提成比例</td>
                        <td colspan="2">
                            <input type="text" class="in_c1" style="width:70px" id="RoleAApr" name="RoleAApr" placeholder="没有就不填" value="@Model.RoleAApr" />%
                        </td>
                    </tr>

                    <tr>
                        <td class="text_w" align="center">B角提成比例</td>
                        <td colspan="1">
                            <input type="text" class="in_c1" style="width:70px" id="RoleBApr" name="RoleBApr" placeholder="没有就不填" value="@Model.RoleBApr" />%
                        </td>

                        <td class="text_w" align="center">B角</td>
                        <td colspan="2">
                            <input type="text" class="in_c1" style="width:70px" id="BName" readonly="readonly" name="BName" value="@ViewBag.BName" placeholder="没有就不填" />
                            <input id="RoleBID" type="hidden" name="RoleBID" value="@Model.RoleBID" />
                            <a href="javascript:void(0)" class="btn_c3 " onclick="addBUsers()">添加</a>
                        </td>
                    </tr>
                </table>
            }
        </div>
    </div>

    <script src=@Url.Content("/Scripts/jquery.form.js") type="text/javascript"></script>
    <script src=@Url.Content("/Scripts/FCDB.form.js?v=20170821") type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#frm").validationEngine({ promptPosition: "topLeft" });
            $("#FormDate").kendoDatePicker({
                format: "yyyy-MM-dd",
                value: new Date()
            });
            $("#AchievementTime").kendoDatePicker({
                format: "yyyy-MM",

            });

            $("#ChargingDate").kendoDatePicker({
                format: "yyyy-MM-dd",

            });
            $("#RebateTime").kendoDatePicker({
                format: "yyyy-MM-dd",

            });
            $("#IsInvoice").change(function () {
                CalRate();
            });
            $("#GuaranteeType").change(function () {
                showDL();
            });

            $("#BillType").val("@Model.Amount");
            $("#ContractType").val("@Model.Amount");
            var kendo = $("#FormDate").data("kendoDatePicker");
            var formStatus = $("#hStatus").val();

            var ProccessActiveContainerList = $(".ProccessActiveContainer");
            if (ProccessActiveContainerList.length > 0) {
                $.each(ProccessActiveContainerList, function (i, item) {
                    var divId = $(item).attr("id");
                    var frmID = divId.slice(3);
                    $("#" + frmID).appendTo(item);
                    $("#" + frmID + " select").attr("disabled", "disabled");
                    $("#" + frmID + " input").attr("disabled", "disabled");
                    $("#" + frmID).show();
                });
                $(".curentContainer form select").removeAttr("disabled");
                $(".curentContainer form input").removeAttr("disabled");
            }
        });



        function Save() {
            var formStatus = $("#hStatus").val();

            var flag = $('#frm').validationEngine('validate');
            if (!flag) return false;
            var FormConditionValue = JSON.stringify(GetFormCondition());
            var options = {
                data: {
                    FormAttachement: GetFormAttachement()
                },
                success: function (data) {
                    alert("表单保存成功");
                    window.close();
                }
            };
            $("#frm").ajaxSubmit(options);

        }
        function SaveAsDraft() {
            var flag = $('#frm').validationEngine('validate');
            var options = {
                data: { FormAttachement: GetFormAttachement(), FormsRelation: GetFormsRelation() },
                success: function (data) {
                    alert("保存成功");
                    window.close();
                }
            };
            $("#hStatus").val("1");
            $("#frm").ajaxSubmit(options);
        }
        function CalRate() {
            var Amount = $("#Amount").val();
            // 合同收款
            var ContractAmount = $("#ContractAmount").val();
            var Rate = (ContractAmount * 1.0) / Amount * 100;
            $("#Rate").val(Rate.toFixed(2));

            var ActualCharge = $("#ActualCharge").val();
            var ActualRate = (ActualCharge * 1.0) / Amount * 100;
            $("#ActualRate").val(ActualRate.toFixed(2));

            // 实际收费=合同收款-应付佣金
            var PayableAmount = $("#PayableAmount").val();
            var ActualCharge = ContractAmount - PayableAmount;
            $("#ActualCharge").val(ActualCharge.toFixed(2));
            var ActualCharge = $("#ActualCharge").val();

            var ActualRate = (ActualCharge * 1.0) / Amount * 100;
            $("#ActualRate").val(ActualRate.toFixed(2));

            $("#taxation").html(PayableAmount * 0.1);
            if ($("#IsInvoice").val() == "true") {
                $("#showStatus").attr("style", "");
                $("#agencyFee").html(PayableAmount * 0.9);
            } else {
                $("#showStatus").attr("style", "display:none");
                $("#agencyFee").html(PayableAmount);
            }

        }

        function showDL() {
            if ($("#GuaranteeType ").val() == "一般案件") {
                $(".showBX").attr("style", "display:none");
                $(".showLB").attr("style", "display:none");
            }
            if ($("#GuaranteeType ").val() == "联保案件") {
                $(".showBX").attr("style", "display:none");
                $(".showLB").attr("style", "");
            }
            if ($("#GuaranteeType ").val() == "保险案件") {
                $(".showBX").attr("style", "");
                $(".showLB").attr("style", "display:none");
            }
        }

        function addUsers() {
            var url = '@Url.Action("EmployeeSelect", "Employee")';
            OpenSelectUserPop(url, RefreshValue);
        }
        function RefreshValue(selectPostList) {
            if (selectPostList != null || selectPostList != undefined) {
                var strNames = "";
                var strUserIDs = "";
                $.each(selectPostList, function (i, val) {
                    strNames = val.Name;
                    strUserIDs = val.UserID;
                    $("#ShowSalesman").val(strNames);
                    $("#Salesman").val(strUserIDs);
                });
            }
        }
    </script>


